<template>
  <el-upload
    v-bind="$attrs"
    action="#"
    :show-file-list="false"
    :before-upload="handleBeforeUpload"
    :on-success="handleUploadSuccess">
    <template v-for="(item, key) in $slots" :key="key" #[key]>
      <slot :name="key" />
    </template>
  </el-upload>
</template>

<script setup>
const emit = defineEmits(['beforeUpload', 'onSuccess'])
function handleBeforeUpload(file) {
  return new Promise((resolve, reject) => {
    emit('beforeUpload', file, ()=>{

    })
  })
}


function handleUploadSuccess({ url, path }, file, files){
  emit('onSuccess',{
    url,
    path,
    file,
    files,
  })
  ElMessage.success('上传成功!')
}
</script>

<style>
</style>
